// import { msmReceiveMap } from '@/config/dict'
export const queryFormItem = [
  {
    type: 'date',
    key: 'beginDate',
    otherAttrs: {
      style: {
        width: '140px'
      },
      placeholder: '开始日期'
    }
  },
  {
    type: 'date',
    key: 'endDate',
    otherAttrs: {
      style: {
        width: '140px'
      },
      placeholder: '结束日期'
    }
  },
  {
    type: 'select',
    key: 'receiver',
    options: [],
    otherAttrs: {
      style: {
        width: '110px'
      },
      placeholder: '接收人'
    }
  },
  {
    type: 'input',
    key: 'keyword',
    otherAttrs: {
      style: {
        width: '200px'
      },
      placeholder: '请输入业务名称或标题关键字'
    }
  }
]

// 处理人数过多
const filterNumPeople = value => {
  var exportValue = ''
  const result = value.split(',')
  if (result.length >= 3) {
    exportValue = `（共${result.length}人）${result.slice(0, 3).join('、')}...`
  } else {
    exportValue = result.join('、')
  }
  return exportValue
}
export const tableColumn = (page, size, handleReceiver, handleBusinessName) => {
  return [
    {
      key: 'businessName',
      label: '业务名称',
      minWidth: 260,
      render: (h, scope) => (
        <el-link onClick={() => handleBusinessName(scope.row)}>
          {filterNumPeople(scope.row.businessName)}
        </el-link>
      )
    },
    {
      key: 'title',
      label: '数据报告标题',
      minWidth: 140
    },
    {
      key: 'receiverDesc',
      label: '接收人',
      minWidth: 170,
      render: (h, scope) => (
        <el-link onClick={() => handleReceiver(scope.row)}>
          {filterNumPeople(scope.row.receiverDesc)}
        </el-link>
      )
    },
    {
      key: 'createTime',
      label: '生成时间',
      minWidth: 140
    }
  ]
}

// 处理状态的文字和状态显示
const formatStatusName = scope => {
  let name = ''
  let color = ''
  switch (scope.row.status) {
    case 1:
      name = '成功'
      break
    case 2:
      name = '失败'
      color = '#f00'
      break
    case 3:
      name = '未发送'
      break
    default:
      break
  }
  return { name, color }
}

// 接收人弹窗
export const receiverTableColumn = (page, size) => {
  return [
    // {
    //   key: 'N0',
    //   label: 'No',
    //   minWidth: 120
    // },
    {
      key: 'deptName',
      label: '部门',
      minWidth: 120
    },
    {
      key: 'accountName',
      label: '姓名',
      minWidth: 120
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 120,
      render: (h, scope) => (
        <span style={'color: ' + formatStatusName(scope).color}>
          {formatStatusName(scope).name}
        </span>
      )
    },
    {
      key: 'failReason',
      label: '失败原因',
      minWidth: 200
    }
  ]
}
